<script setup>
import { findNewAPI } from '@/apis/home'
import { onMounted, ref } from 'vue'

//获取数据
const newList = ref([])
findNewAPI()
const getNewList = async () => {

  const res = await findNewAPI()
  newList.value = res.result
  console.log(newList.value)

}

onMounted(() => getNewList())
</script>

<template>
  <div class="home-panel">
    <div class="container">
      <div class="head">
        <!-- 主标题和副标题 -->
        <h3>
          甄选推荐
        </h3>
      </div>
      <!-- 主体内容区域 -->
      <div>

        <ul class="goods-list">
          <li v-for="item in newList" :key="item.id">
            <RouterLink :to="`/detail/${item.id}`">
              <img  :src="item.picture" alt="" />
              <p class="name">{{ item.name }}</p>
              <p class="price">&yen;{{ item.price }}</p>
            </RouterLink>
          </li>

        </ul>
        <ul class="goods-list">
          <li v-for="item in newList" :key="item.id">
            <RouterLink :to="`/detail/${item.id}`">
              <img v-lazy-img="item.picture"  alt="" />
              <p class="name">{{ item.name }}</p>
              <p class="price">&yen;{{ item.price }}</p>
            </RouterLink>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>


<style scoped lang='scss'>
.home-panel {
  margin-top: 20px;

  .head {
    padding: 40px 0;
    display: flex;
    align-items: flex-end;

    h3 {
      flex: 1;
      font-size: 32px;
      font-weight: normal;
      margin-left: 6px;
      height: 35px;
      line-height: 35px;
    }
  }
}

.goods-list {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  width: 1250px;
  height: 406px;
  padding-right: 20px;

  li {
    width: 296px;
    height: 406px;
    margin-bottom: 15px;
    background: #fafbfa;
    transition: all .5s;

    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }

    img {
      width: 100%;
      height: 306px;
    }

    p {
      font-size: 15px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }

    .desc {
      align-content: center;
      font-size: 10px;
    }

    .price {
      color: $priceColor;
    }
  }
}</style>